<template>
  <el-row :gutter="16" class="panel-group">
    <el-col :xs="6" :sm="6" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <a title="查看明细">
          <router-link to="/userflow/waitApprove">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="message" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">待审批</div>
              <count-to :start-val="0" :end-val="count.waitApproveNum" :duration="1500" class="card-panel-num"/>
            </div>
          </router-link>
        </a>
      </div>
    </el-col>
    <el-col :xs="6" :sm="6" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <a title="查看明细">
          <router-link to="/user/task">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="edit" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">待处理任务</div>
              <count-to :start-val="0" :end-val="count.waitTaskNum" :duration="1500" class="card-panel-num"/>
            </div>
          </router-link>
        </a>
      </div>
    </el-col>
    <el-col v-permission="['SYS_ADMIN','COMMON_ADMIN','DASHBOARD_CLUE_INFO']" :xs="6" :sm="6" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <a title="查看明细">
          <router-link to="/crm/clue">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="chain" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">今日新增线索</div>
              <count-to :start-val="0" :end-val="count.todayClueNum" :duration="1500" class="card-panel-num"/>
            </div>
          </router-link>
        </a>
      </div>
    </el-col>
    <el-col v-permission="['SYS_ADMIN','COMMON_ADMIN','DASHBOARD_CONTRACT_INFO']" :xs="6" :sm="6" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <a title="查看明细">
          <router-link to="/crm/contract">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="education" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <div class="card-panel-text">今日新增合同</div>
              <count-to :start-val="0" :end-val="count.todayContractNum" :duration="1500" class="card-panel-num"/>
            </div>
          </router-link>
        </a>
      </div>
    </el-col>
    <el-col v-permission="['SYS_ADMIN','COMMON_ADMIN','DASHBOARD_CUSTOM_INFO']" :xs="6" :sm="6" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="people" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <el-row :gutter="8">
            <el-col :span="12">
              <a title="查看明细">
                <router-link to="/crm/custom">
                  <div class="card-panel-text">今新增</div>
                  <count-to :start-val="0" :end-val="count.todayCustomNum" :duration="1500" class="card-panel-num"/>
                </router-link>
              </a>
            </el-col>
            <el-col :span="12">
              <a title="查看明细">
                <router-link to="/crm/custom">
                  <div class="card-panel-text">昨成交</div>
                  <count-to :start-val="0" :end-val="count.yesterdayDealCustomNum" :duration="1500" class="card-panel-num"/>
                </router-link>
              </a>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-col>
    <el-col v-permission="['SYS_ADMIN','COMMON_ADMIN','DASHBOARD_SALE_INFO']" :xs="6" :sm="6" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-message">
          <svg-icon icon-class="international" class-name="card-panel-icon" />
        </div>
        <a title="查看明细">
          <router-link to="/sale/order">
            <div class="card-panel-description">
              <div class="card-panel-text">近一月销售金额/笔数</div>
              <count-to :start-val="0" :end-val="count.saleTotalMoney" :duration="1500" class="card-panel-num"/>
              /
              <count-to :start-val="0" :end-val="count.saleTotalNum" :duration="1500" class="card-panel-num"/>
            </div>
          </router-link>
        </a>
      </div>
    </el-col>
    <el-col v-permission="['SYS_ADMIN','COMMON_ADMIN','DASHBOARD_PURCHASE_INFO']" :xs="6" :sm="6" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-people">
          <svg-icon icon-class="web" class-name="card-panel-icon" />
        </div>
        <a title="查看明细">
          <router-link to="/purchase/po">
            <div class="card-panel-description">
              <div class="card-panel-text">近一月采购金额/笔数</div>
              <count-to :start-val="0" :end-val="count.purchaseTotalMoney" :duration="1500" class="card-panel-num"/>
              /
              <count-to :start-val="0" :end-val="count.purchaseTotalNum" :duration="1500" class="card-panel-num"/>
            </div>
          </router-link>
        </a>
      </div>
    </el-col>
    <el-col v-permission="['SYS_ADMIN','COMMON_ADMIN','DASHBOARD_FIN_INFO']" :xs="6" :sm="6" :lg="6" class="card-panel-col">
      <div class="card-panel">
        <div class="card-panel-icon-wrapper icon-money">
          <svg-icon icon-class="monitor" class-name="card-panel-icon" />
        </div>
        <div class="card-panel-description">
          <el-row :gutter="8">
            <el-col :span="12">
              <a title="查看明细">
                <router-link to="/fin/finwaitorder">
                  <div class="card-panel-text">待收款</div>
                  <count-to :start-val="0" :end-val="count.saleRcvWaitMoney" :duration="1500" class="card-panel-num"/>
                </router-link>
              </a>
            </el-col>
            <el-col :span="12">
              <a title="查看明细">
                <router-link to="/fin/finwaitpo">
                  <div class="card-panel-text">待付款</div>
                  <count-to :start-val="0" :end-val="count.purchasePayWaitMoney" :duration="1500" class="card-panel-num"/>
                </router-link>
              </a>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-col>
  </el-row>
</template>

<script>
import CountTo from 'vue-count-to'
import { getApproveTaskNum } from '@/api/system/workflowApprove'
import order from '@/api/business/Order'
import po from '@/api/business/Po'
import finWait from '@/api/fin/FinWait'
import checkPermission from '@/utils/permission'
import task from '@/api/crm/Task'
import clue from '@/api/crm/Clue'
import contract from '@/api/crm/Contract'
import custom from '@/api/crm/Custom'

export default {
  checkPermission,
  components: {
    CountTo
  },
  data() {
    return {
      count: {
        waitApproveNum: 0,
        waitTaskNum: 0,
        todayClueNum: 0,
        todayCustomNum: 0,
        yesterdayDealCustomNum: 0,
        todayContractNum: 0,
        saleTotalNum: 0,
        saleTotalMoney: 0,
        saleRcvWaitMoney: 0,
        purchaseTotalNum: 0,
        purchaseTotalMoney: 0,
        purchasePayWaitMoney: 0
      }
    }
  },
  mounted() {
    getApproveTaskNum().then(res => {
      this.count.waitApproveNum = res.data
    })

    task.findWaitTaskCountByChargerId().then(res => {
      this.count.waitTaskNum = res.data
    })

    if (checkPermission(['SYS_ADMIN', 'COMMON_ADMIN', 'DASHBOARD_CLUE_INFO'])) {
      clue.findCreateClueNum().then(res => {
        this.count.todayClueNum = res.data
      })
    }
    if (checkPermission(['SYS_ADMIN', 'COMMON_ADMIN', 'DASHBOARD_CUSTOM_INFO'])) {
      custom.findCreateCustomNum().then(res => {
        this.count.todayCustomNum = res.data.todayCustomNum
        this.count.yesterdayDealCustomNum = res.data.yesterdayDealCustomNum
      })
    }
    if (checkPermission(['SYS_ADMIN', 'COMMON_ADMIN', 'DASHBOARD_CONTRACT_INFO'])) {
      contract.findCreateContractNum().then(res => {
        this.count.todayContractNum = res.data
      })
    }
    if (checkPermission(['SYS_ADMIN', 'COMMON_ADMIN', 'DASHBOARD_SALE_INFO'])) {
      order.getRequestByName('getOrderStatInfo', null).then(res => {
        this.count.saleTotalNum = res.data.totalQty || 0
        this.count.saleTotalMoney = res.data.totalMoney || 0
      })
    }
    if (checkPermission(['SYS_ADMIN', 'COMMON_ADMIN', 'DASHBOARD_PURCHASE_INFO'])) {
      po.getRequestByName('getPoStatInfo', null).then(res => {
        this.count.purchaseTotalNum = res.data.totalQty || 0
        this.count.purchaseTotalMoney = res.data.totalMoney || 0
      })
    }
    if (checkPermission(['SYS_ADMIN', 'COMMON_ADMIN', 'DASHBOARD_FIN_INFO'])) {
      finWait.getRequestByName('getWaitStatInfo', null).then(res => {
        res.data.forEach(tmpvo => {
          if (tmpvo.sourceBusClass === '600004-001') {
            this.count.purchasePayWaitMoney = tmpvo.processMoney || 0
          } else if (tmpvo.sourceBusClass === '600005-001') {
            this.count.saleRcvWaitMoney = tmpvo.processMoney || 0
          }
        })
      })
    }
  },
  methods: {
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.panel-group {
  margin-top: 8px;
  .card-panel-col{
    margin-bottom: 32px;
  }
  .card-panel {
    height: 108px;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 10px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);
    .icon-people {
      color: #40c9c6;
    }
    .icon-message {
      color: #36a3f7;
    }
    .icon-money {
      color: #f4516c;
    }
    .icon-shopping {
      color: #34bfa3
    }
    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }
    .card-panel-icon {
      float: left;
      font-size: 48px;
    }
    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;
      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }
      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}
</style>
